package cn.itsource.itsource.controller;

import cn.itsource.itsource.config.alipay.AlipayParams;
import cn.itsource.itsource.domain.OrderAdopt;
import cn.itsource.itsource.domain.User;
import cn.itsource.itsource.service.IOrderAdoptService;
import cn.itsource.itsource.service.RedisService;
import cn.itsource.itsource.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/orderadopt")
public class OrderAdoptController {

    @Autowired
    private IOrderAdoptService orderAdoptService;

    @Autowired
    private RedisService redisService;

    @Autowired
    private AlipayParams alipayParams;


    @PostMapping("/submitorder")
    public AjaxResult submitOrder(@RequestBody OrderAdopt orderAdopt, HttpServletRequest request) {
        //获取当前登录的用户ID
        String token = request.getHeader("token");
        User user = redisService.getKeyObjectValue(token, User.class);
        orderAdopt.setUserId(user.getId());

        return orderAdoptService.submitOrder(orderAdopt);
    }


}
